<head>
    <title>项目列表</title>
    <link href="/lego/static/css/bootstrap.css" rel="stylesheet"/>
    <link href="/lego/static/css/header.css" rel="stylesheet"/>
    <link href="/lego/static/css/xcConfirm.css" rel="stylesheet"/>
    <style>
        #projectListTable{
            margin-left: 200px;
            margin-right: 200px;
        }
    </style>
    <script src="/lego/static/js/jquery.1.11.3.min.js"></script>
    <script src = "/lego/static/js/bootstrap.js" ></script>
    <script src="/lego/static/js/underscore-min.js"></script>
    <script src="/lego/static/js/xcConfirm.js"></script>
    <script type="text/javascript">
        $(function () {
            initData();
        });

        //初始化表格数据
        function initData() {
            $.ajax({
                url: '/lego/getAllProject',
                type: 'GET',
                success: function (data) {
                    if (data && data.code == 200) {
                        $('#projectListTable').html(_.template($('#projectList_template').html())({
                            data: data.data
                        }));
                    }
                }
            });
        }

        function editProject(projectId) {
            $.ajax({
                url: '/lego/confirmEditProjectPermission',
                type: 'post',
                data:{"projectId":projectId},
                success: function (data) {
                    if (data && data.code == 200) {
                        if(data.msg != "验证通过"){
                            window.wxc.xcConfirm(data.msg,window.wxc.xcConfirm.typeEnum.error);
                        }else {
                            window.location.href = "/lego/editProjectIndex/" + projectId;
                        }
                    }
                }
            });
        }

        function deleteProject(projectId) {
            var option = {
                title: "提示信息",
                btn:window.wxc.xcConfirm.btnEnum.okcancel ,
                onOk: function(){
                    $.ajax({
                        url: '/lego/validateBeforeDeleteProject',
                        type: 'GET',
                        data:{"projectId":projectId},
                        success: function (data) {
                            if (data && data.code == 200) {
                                var op = {
                                    title: "提示信息",
                                    btn: window.wxc.xcConfirm.btnEnum.okcancel,
                                    onOk: function(){
                                        actualDeleteProject(projectId);
                                    }
                                }
                                if(data.msg == "验证通过"){
                                    actualDeleteProject(projectId);
                                }else {
                                    window.wxc.xcConfirm(data.msg,window.wxc.xcConfirm.typeEnum.custom, op);
                                }
                            }
                        }
                    });
                }
            }
            window.wxc.xcConfirm("确认删除该项目吗?", window.wxc.xcConfirm.typeEnum.warning, option);
        }

        function actualDeleteProject(projectId) {
            $.ajax({
                url: '/lego/deleteProject',
                type: 'post',
                data:{"projectId":projectId},
                success: function (data) {
                    if (data && data.code == 200) {
                        var op = {
                            title: "提示信息",
                            btn: window.wxc.xcConfirm.btnEnum.ok,
                            onOk: function(){
                                initData();
                            }
                        }
                        if(data.msg == "删除成功"){
                            window.wxc.xcConfirm(data.msg,window.wxc.xcConfirm.typeEnum.success, op);
                        }else {
                            window.wxc.xcConfirm(data.msg,window.wxc.xcConfirm.typeEnum.error, op);
                        }
                    }
                }
            });
        }
    </script>
</head>
<body>
<#include "../navigationBar.ftl">
<header class="jumbotron subhead" id="overview">
    <div class="container">
        <h1>项目信息管理</h1>
    </div>
</header>

<div class="text-right" style="margin-right: 200px;margin-bottom: 20px">
    <a class="btn btn-primary" href="/lego/addProjectIndex" target="_blank">
        <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>添加项目
    </a>
</div>
<div id="projectListTable"></div>
<#include "../common/template.ftl">
</body>
